package com.lxu.jdbc.service;

import com.lxu.jdbc.dao.JDBCDao;
import com.lxu.jdbc.utils.JDBCUtil;

import java.sql.Connection;

public class CommonService {

    public void transfer(String inUser, String outUser, int money) {
        Connection conn = null;
        try {
            conn = JDBCUtil.getConnection();
            conn.setAutoCommit(false);
            JDBCDao jdbcDao = new JDBCDao();
            jdbcDao.out(inUser, money,conn);
            int i = 1 / 0;
            jdbcDao.in(outUser, money,conn);
            JDBCUtil.commitAndClose(conn);
        } catch (Exception e) {
            e.printStackTrace();
            if (conn != null) {
                JDBCUtil.rollbackAndClose(conn);
            }
        }
    }

}
